package com.fmy.jurisdiction.config.spring.web.jackson;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.sql.Timestamp;

/**
 * <p>
 * Timestamp类型转换类
 * <p>
 *
 * @ClassName CustomObjectMapper
 * @Aulthor Mr.fmy
 * @Version 1.0
 * @Date 2019/8/28 17:40
 **/
public class TimestampSerializer extends JsonSerializer<Timestamp> {

    @Override
    public void serialize(Timestamp timestamp, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
        jsonGenerator.writeString(DateUtil.formatDateTime(timestamp));
    }
}
